var positionObj = {
    addPositionData() {
        var url = "http://localhost:3000/positionDataList";
        axios.get(url).then(function (res) {
          positionObj.positionList(res.data);
        

        });
      },
      positionList(list) {
      var str = "";
        list.forEach(function (item) {
          str += `
          <a href="./job-details.html?id=${item.id}" class="work-list flex bg-fff w100p mt-10">
              <ul class="list w100p">
                <li class="item w100p">
                  <p class="flex jc-sb">
                    <span style="width: 260px;
                    white-space: nowrap; 
                    overflow: hidden; 
                    text-overflow: ellipsis; ">${item.workTitle}</span>
                    <span class="sc f12">推广</span>
                  </p>
                  <p class="flex jc-sb">
                    <span class="sc">${item.price}</span>
                    <span class="f12 c888">${item.time}</span>
                  </p>
                  <p class="flex jc-sb aic bb2 pb-20">
                    <span class="condition fcc f12 ">${item.conditionAddress}</span>
                    <span class="condition fcc f12 ">${item.conditionExperience}</span>
                    <span class="condition fcc f12 ">${item.conditionEdu}</span> 
                    <button class="btn fff">申请</button>
                  </p>
                  <p class="company flex aic"><img src="${item.imgUrl}" alt="">
                <span class="f14 ml-10"style="width: 240px;
                    white-space: nowrap; 
                    overflow: hidden; 
                    text-overflow: ellipsis; ">${item.companyName}</span>
                <span class="f12 sc ml-10">认证</span>
                </p>
                </li>
              </ul>
            </a>
          `;
          $('.work').html(str);
        })
      },
      search() {
        $("#submit").click(function () {
          var searchText = $("#searchText").val();
          if(searchText == ""){
              alert("请输入搜索内容");
          }else{
              var url = `http://localhost:3000/positionDataList?q=${searchText}`;
          axios
            .get(url)
            .then(function (res) {
              positionObj.render(res.data);
            })
            .catch(function (err) {
              console.log("查询失败", err);
            });
          } 
        });
      },
      render(list) {
        var htmlStr = "";
        list.forEach(function (item) {
          htmlStr += `
               <a href="./job-details.html?id=${item.id}" class="work-list flex bg-fff w100p mt-10">
              <ul class="list w100p">
                <li class="item w100p">
                  <p class="flex jc-sb">
                    <span style="width: 260px;
                    white-space: nowrap; 
                    overflow: hidden; 
                    text-overflow: ellipsis; ">${item.workTitle}</span>
                    <span class="sc f12">推广</span>
                  </p>
                  <p class="flex jc-sb">
                    <span class="sc">${item.price}</span>
                    <span class="f12 c888">${item.time}</span>
                  </p>
                  <p class="flex jc-sb aic bb2 pb-20">
                    <span class="condition fcc f12 ">${item.conditionAddress}</span>
                    <span class="condition fcc f12 ">${item.conditionExperience}</span>
                    <span class="condition fcc f12 ">${item.conditionEdu}</span> 
                    <button class="btn fff">申请</button>
                  </p>
                  <p class="company flex aic"><img src="${item.imgUrl}" alt="">
                <span class="f14 ml-10"style="width: 240px;
                    white-space: nowrap; 
                    overflow: hidden; 
                    text-overflow: ellipsis; ">${item.companyName}</span>
                <span class="f12 sc ml-10">认证</span>
                </p>
                </li>
              </ul>
            </a>
              `;
        });
        $(".work").html(htmlStr);
      }
}
positionObj.search();